package com.yonyou.ucf.mdf.app.isvdxq.other.service;

import com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl.UserstaffMapperImpl;
import com.yonyou.ucf.mdf.app.isvdxq.yonyisv.model.EventContent;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.UserstaffEntity;
import com.yonyou.ucf.mdf.app.isvdxq.other.model.ContentBean;
import com.yonyou.ucf.mdf.app.isvdxq.utils.RequestTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;


@Service
public class UserstaffService {
    @Autowired
    private UserstaffMapperImpl userstaffMapper;

    public UserstaffEntity SelectById(Long Id) {
        return userstaffMapper.selectById(Id);
    }

    public Boolean CheckEntity(Long Id) {
        int rInt = userstaffMapper.selectCount(Id);
        if (rInt > 0) return true;
        else return false;
    }

    public Integer InsertEntity(UserstaffEntity entity) {
        return userstaffMapper.insert(entity);
    }

    public Integer UpdateEntity(UserstaffEntity entity) {
        return userstaffMapper.updateByPrimaryKey(entity);
    }

    public List<UserstaffEntity> SelectAll() {
        return userstaffMapper.selectAll();
    }

    public List<UserstaffEntity> SelectByTenantId(String tenantId) {
        return userstaffMapper.selectByTenantId(tenantId);
    }

    public Integer DeleteById(Long Id) {
        return userstaffMapper.deleteByPrimaryKey(Id);
    }

    public Integer EventDel(EventContent content) throws IOException {
        System.out.println(content.getContent());
        ContentBean obj = RequestTool.getBean(content.getContent(), ContentBean.class);
        Long Id = Long.parseLong(obj.getId());
        Boolean flag = CheckEntity(Id);
        if (flag) {
            int rInt = DeleteById(Id);
            return rInt;
        }
        return 0;
    }

    /**
     * 友互通UserId查询数据
     *
     * @param yhtUserId
     * @return
     */
    public UserstaffEntity SelectByUserId(String yhtUserId) {
        return userstaffMapper.SelectByUserId(yhtUserId);
    }
    public UserstaffEntity SelectByMobile(String tenantId, String mobile){
        return userstaffMapper.SelectByMobile(tenantId, mobile);
    }
    public List<UserstaffEntity> SelectAllByMobile(String mobile){
        return userstaffMapper.selectAllByMobile(mobile);
    }
    public UserstaffEntity SelectByTenantKey(String tenantId, String yhtUserId){
        return userstaffMapper.SelectByTenantKey(tenantId, yhtUserId);
    }

    /**
     * 友互通UserId查询数据,批量查询
     * @param yhtUserIds  友互通UserId(creatorId\modifierId)
     * @param tenantId
     * @return
     */
    public List<UserstaffEntity> SelectByYhtUserIds(String[] yhtUserIds, String tenantId){
        return userstaffMapper.selectUserListByYhtUserIds(yhtUserIds, tenantId);
    }
}
